package com.awenhui.demo.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.awenhui.demo.model.entity.RoleEntity;
import com.awenhui.demo.repository.RoleRespository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 角色服务类
 */
@Service
public class RoleServiceImpl {

    @Autowired
    private RoleRespository roleRespository;

    /**
     * 添加角色
     */
    public RoleEntity addRole() {

        RoleEntity roleEntity = new RoleEntity();
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String id = dateFormat.format(new Date());
        // roleEntity.setId(id);
        roleEntity.setName("系统管理员");
        roleEntity.setCreateTime(new Date());
        roleRespository.save(roleEntity);
        return roleEntity;
    }

    /**
     * 删除角色
     *
     * @param id 角色ID
     */
    public void deleteRole(String id) {
        roleRespository.deleteById(id);
    }

    /**
     * 根据角色名称查询角色
     *
     * @param name
     * @return
     */
    public List<RoleEntity> findByName(String name) {
        List<RoleEntity> roles = roleRespository.findByName(name);
        return roles;
    }

}